namespace InventoryManagement
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.ComponentModel;
	using System.Data;
	using System.Data.SqlClient;
	using System.Text;
	
	
	public class Approval : BaseTable
	{
		
		#region Static SQL String Members
		/// <remarks>This field represents the full SELECT string for the table Approval, with the WHERE clause.</remarks>
		internal static string _SQL_Select = "SELECT [ID], [IDChild], [ApprovalDate], [Approver], [Modul], [URL], [Action], [Comment], [Requester], [RequestDate] FROM [dbo].[Approval] WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the full SELECT string for the table Approval, with the WHERE clause.</remarks>
		internal static string _SQL_SelectByParam = @"SELECT [ID], [IDChild], [ApprovalDate], [Approver], [Modul], [URL], [Action], [Comment], [Requester], [RequestDate] FROM [dbo].[Approval] WHERE isnull(convert(varchar(36),[ID]),'true')=isnull(convert(varchar(36),@ID),isnull(convert(varchar(36),[ID]),'true')) AND isnull(convert(varchar(36),[IDChild]),'true')=isnull(convert(varchar(36),@IDChild),isnull(convert(varchar(36),[IDChild]),'true')) AND isnull(convert(varchar,[ApprovalDate]),'true')=isnull(convert(varchar,@ApprovalDate),isnull(convert(varchar,[ApprovalDate]),'true')) AND isnull(convert(varchar,[Approver]),'true')=isnull(convert(varchar,@Approver),isnull(convert(varchar,[Approver]),'true')) AND isnull(convert(varchar,[Modul]),'true')=isnull(convert(varchar,@Modul),isnull(convert(varchar,[Modul]),'true')) AND isnull(convert(varchar,[URL]),'true')=isnull(convert(varchar,@URL),isnull(convert(varchar,[URL]),'true')) AND isnull(convert(varchar,[Action]),'true')=isnull(convert(varchar,@Action),isnull(convert(varchar,[Action]),'true')) AND isnull(convert(varchar,[Comment]),'true')=isnull(convert(varchar,@Comment),isnull(convert(varchar,[Comment]),'true')) AND isnull(convert(varchar,[Requester]),'true')=isnull(convert(varchar,@Requester),isnull(convert(varchar,[Requester]),'true')) AND isnull(convert(varchar,[RequestDate]),'true')=isnull(convert(varchar,@RequestDate),isnull(convert(varchar,[RequestDate]),'true')) ";
		
		/// <remarks>This field represents the full INSERT INTO string for the table Approval.</remarks>
		internal static string _SQL_Insert = "INSERT INTO [dbo].[Approval] ([ID], [IDChild], [ApprovalDate], [Approver], [Modul], [URL], [Action], [Comment], [Requester], [RequestDate]) VALUES(@ID, @IDChild, @ApprovalDate, @Approver, @Modul, @URL, @Action, @Comment, @Requester, @RequestDate) ";
		
		/// <remarks>This field represents the full UPDATE string for the table Approval, with the WHERE clause.</remarks>
		internal static string _SQL_Update = @"UPDATE [dbo].[Approval] SET [ID] = @ID, [IDChild] = @IDChild, [ApprovalDate] = @ApprovalDate, [Approver] = @Approver, [Modul] = @Modul, [URL] = @URL, [Action] = @Action, [Comment] = @Comment, [Requester] = @Requester, [RequestDate] = @RequestDate WHERE [ID]=@ID ";
		
		/// <remarks>This field represents the DELETE string for the table Approval, with the WHERE clause.</remarks>
		internal static string _SQL_Delete = "DELETE FROM [dbo].[Approval] WHERE [ID]=@ID ";
		#endregion
		
		#region Tables Members
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _ID;
		
		[DisplayName("ID")]
		[Category("Primary Key")]
		public System.Nullable<System.Guid> ID
		{
			get
			{
				try
				{
					return _ID;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ID", err);
				}
			}
			set
			{
				try
				{
					_ID = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ID", err);
				}
			}
		}
		
		/// <remarks>SQL Type:uniqueidentifier - </remarks>
		private System.Nullable<System.Guid> _IDChild;
		
		[DisplayName("IDChild")]
		[Category("Column")]
		public System.Nullable<System.Guid> IDChild
		{
			get
			{
				try
				{
					return _IDChild;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting IDChild", err);
				}
			}
			set
			{
				try
				{
					_IDChild = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting IDChild", err);
				}
			}
		}
		
		/// <remarks>SQL Type:datetime - </remarks>
		private System.Nullable<System.DateTime> _ApprovalDate;
		
		[DisplayName("Approval Date")]
		[Category("Column")]
		public System.Nullable<System.DateTime> ApprovalDate
		{
			get
			{
				try
				{
					return _ApprovalDate;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting ApprovalDate", err);
				}
			}
			set
			{
				try
				{
					_ApprovalDate = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting ApprovalDate", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Approver;
		
		[DisplayName("Approver")]
		[Category("Column")]
		public string Approver
		{
			get
			{
				try
				{
					return _Approver;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Approver", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Approver = value;
					}
					else
					{
						throw new OverflowException("Error setting Approver, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Approver", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Modul;
		
		[DisplayName("Modul")]
		[Category("Column")]
		public string Modul
		{
			get
			{
				try
				{
					return _Modul;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Modul", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Modul = value;
					}
					else
					{
						throw new OverflowException("Error setting Modul, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Modul", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _URL;
		
		[DisplayName("URL")]
		[Category("Column")]
		public string URL
		{
			get
			{
				try
				{
					return _URL;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting URL", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 400))
					{
						_URL = value;
					}
					else
					{
						throw new OverflowException("Error setting URL, Length of value is to long. Maximum Length: 400");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting URL", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Action;
		
		[DisplayName("Action")]
		[Category("Column")]
		public string Action
		{
			get
			{
				try
				{
					return _Action;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Action", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Action = value;
					}
					else
					{
						throw new OverflowException("Error setting Action, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Action", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Comment;
		
		[DisplayName("Comment")]
		[Category("Column")]
		public string Comment
		{
			get
			{
				try
				{
					return _Comment;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Comment", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length < 2147483647))
					{
						_Comment = value;
					}
					else
					{
						throw new OverflowException("Error setting Comment, Length of value is to long.");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Comment", err);
				}
			}
		}
		
		/// <remarks>SQL Type:varchar - </remarks>
		private string _Requester;
		
		[DisplayName("Requester")]
		[Category("Column")]
		public string Requester
		{
			get
			{
				try
				{
					return _Requester;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting Requester", err);
				}
			}
			set
			{
				try
				{
					if ((value.Length <= 200))
					{
						_Requester = value;
					}
					else
					{
						throw new OverflowException("Error setting Requester, Length of value is to long. Maximum Length: 200");
					}
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting Requester", err);
				}
			}
		}
		
		/// <remarks>SQL Type:datetime - </remarks>
		private System.Nullable<System.DateTime> _RequestDate;
		
		[DisplayName("Request Date")]
		[Category("Column")]
		public System.Nullable<System.DateTime> RequestDate
		{
			get
			{
				try
				{
					return _RequestDate;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error getting RequestDate", err);
				}
			}
			set
			{
				try
				{
					_RequestDate = value;
				}
				catch (System.Exception err)
				{
					throw new Exception("Error setting RequestDate", err);
				}
			}
		}
		#endregion
		
		#region Public Methods
		public void Select()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Approval._SQL_Select;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataReader rs = Com.ExecuteReader();
				while(rs.Read())
				{
					AddFromRecordSet(rs);
				}
				rs.Close();
				Conn.Close();
				rs.Dispose();
				Com.Dispose();
				Conn.Dispose();
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public System.Data.DataTable SelectByParam()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Approval._SQL_SelectByParam;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				SqlDataAdapter objDataAdapter = new SqlDataAdapter(Com);
				DataTable objDataTable = new DataTable();
				objDataAdapter.Fill(objDataTable);
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return objDataTable;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Insert()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Approval._SQL_Insert;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Update()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Approval._SQL_Update;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public int Delete()
		{
			try
			{
				SqlConnection Conn = new SqlConnection(_connString);
				SqlCommand Com = Conn.CreateCommand();
				Com.CommandText = Approval._SQL_Delete;
				Com.Parameters.AddRange(GetSqlParameters());
				Conn.Open();
				int rowseffected = Com.ExecuteNonQuery();
				Conn.Close();
				Com.Dispose();
				Conn.Dispose();
				return rowseffected;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		
		public string[] GetSqlCommandStrings()
		{
			try
			{
				string[] CommStr = new string[4];
				CommStr[0] = "SELECT [ID], [IDChild], [ApprovalDate], [Approver], [Modul], [URL], [Action], [Comment], [Requester], [RequestDate] FROM [dbo].[Approval] WHERE [ID] = " + _ID + "";
				CommStr[1] = "INSERT INTO [dbo].[Approval] ([ID], [IDChild], [ApprovalDate], [Approver], [Modul], [URL], [Action], [Comment], [Requester], [RequestDate]) VALUES(" + _ID + ", " + _IDChild + ", '" + _ApprovalDate + "', '" + _Approver.Replace("'","''") + "', '" + _Modul.Replace("'","''") + "', '" + _URL.Replace("'","''") + "', '" + _Action.Replace("'","''") + "', '" + _Comment.Replace("'","''") + "', '" + _Requester.Replace("'","''") + "', '" + _RequestDate + "')";
				CommStr[2] = "UPDATE [dbo].[Approval] SET [IDChild] = " + _IDChild + " ,[ApprovalDate] = '" + _ApprovalDate + "' ,[Approver] = '" + _Approver.Replace("'","''") + "' ,[Modul] = '" + _Modul.Replace("'","''") + "' ,[URL] = '" + _URL.Replace("'","''") + "' ,[Action] = '" + _Action.Replace("'","''") + "' ,[Comment] = '" + _Comment.Replace("'","''") + "' ,[Requester] = '" + _Requester.Replace("'","''") + "' ,[RequestDate] = '" + _RequestDate + "' WHERE [ID] = " + _ID + "";
				CommStr[3] = "DELETE FROM [dbo].[Approval] WHERE [ID] = " + _ID + "";
				return CommStr;
			}
			catch (System.Exception )
			{
				throw;
			}
		}
		#endregion
		
		#region Private Methods
		private void AddFromRecordSet(SqlDataReader rs)
		{
			try
			{
				// if value from the recordset, to the ID field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ID")) == false))
				{
					ID = rs.GetGuid(rs.GetOrdinal("ID"));
				}
				// if value from the recordset, to the IDChild field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("IDChild")) == false))
				{
					IDChild = rs.GetGuid(rs.GetOrdinal("IDChild"));
				}
				// if value from the recordset, to the ApprovalDate field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("ApprovalDate")) == false))
				{
					ApprovalDate = rs.GetDateTime(rs.GetOrdinal("ApprovalDate"));
				}
				// if value from the recordset, to the Approver field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Approver")) == false))
				{
					Approver = rs.GetString(rs.GetOrdinal("Approver"));
				}
				// if value from the recordset, to the Modul field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Modul")) == false))
				{
					Modul = rs.GetString(rs.GetOrdinal("Modul"));
				}
				// if value from the recordset, to the URL field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("URL")) == false))
				{
					URL = rs.GetString(rs.GetOrdinal("URL"));
				}
				// if value from the recordset, to the Action field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Action")) == false))
				{
					Action = rs.GetString(rs.GetOrdinal("Action"));
				}
				// if value from the recordset, to the Comment field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Comment")) == false))
				{
					Comment = rs.GetString(rs.GetOrdinal("Comment"));
				}
				// if value from the recordset, to the Requester field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("Requester")) == false))
				{
					Requester = rs.GetString(rs.GetOrdinal("Requester"));
				}
				// if value from the recordset, to the RequestDate field is NOT null then set the value.
				if ((rs.IsDBNull(rs.GetOrdinal("RequestDate")) == false))
				{
					RequestDate = rs.GetDateTime(rs.GetOrdinal("RequestDate"));
				}
			}
			catch (SqlException sqlExc)
			{
				throw sqlExc;
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		
		private SqlParameter[] GetSqlParameters()
		{
			List<SqlParameter> SqlParmColl = new List<SqlParameter>();
			try
			{
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ID", ID, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@IDChild", IDChild, SqlDbType.UniqueIdentifier));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@ApprovalDate", ApprovalDate, SqlDbType.DateTime));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Approver", Approver, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Modul", Modul, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@URL", URL, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Action", Action, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Comment", Comment, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@Requester", Requester, SqlDbType.VarChar));
				SqlParmColl.Add(InventoryManagement.AddSqlParm("@RequestDate", RequestDate, SqlDbType.DateTime));
				return SqlParmColl.ToArray();
			}
			catch (Exception Exc)
			{
				throw Exc;
			}
		}
		#endregion
	}
	
	public class ApprovalCollection : System.Collections.CollectionBase
	{
		
		[Description("Adds a new Approval to the collection.")]
		public int Add(Approval item)
		{
			int newindex = List.Add(item);
			return newindex;
		}
		
		[Description("Removes a Approval from the collection.")]
		public void Remove(Approval item)
		{
			List.Remove(item);
		}
		
		[Description("Inserts an Approval into the collection at the specified index.")]
		public void Insert(int index, Approval item)
		{
			List.Insert(index, item);
		}
		
		[Description("Returns the index value of the Approval class in the collection.")]
		public int IndexOf(Approval item)
		{
			return List.IndexOf(item);
		}
		
		[Description("Returns true if the Approval class is present in the collection.")]
		public bool Contains(Approval item)
		{
			return List.Contains(item);
		}
	}
	
	public enum Approval_Fields
	{
		
		ID,
		
		IDChild,
		
		ApprovalDate,
		
		Approver,
		
		Modul,
		
		URL,
		
		Action,
		
		Comment,
		
		Requester,
		
		RequestDate,
	}
}
